package com.zhang.bingmei_incomeexpenditure.service.strategy.Impl;

import com.zhang.bingmei_incomeexpenditure.entity.Utils.SecurityPlusUtils;
import com.zhang.bingmei_incomeexpenditure.entity.commom.DataScope;
import com.zhang.bingmei_incomeexpenditure.service.strategy.DataScopeStrategy;
import org.apache.commons.lang3.StringUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

// 市县级管理员策略（角色3）
public class CityDataScopeStrategy implements DataScopeStrategy {
    @Override
    public DataScope getAreaPrefix() {
        // 从Security工具类获取当前用户区域
        String area = SecurityPlusUtils.getArea();
        DataScope dataScope = new DataScope();
        dataScope.setArea(area);
        dataScope.setMinLevel(3);
        return dataScope;
    }

    @Override
    public List<String> buildFullDistrictCodes(List<String> districtSuffixList) {
        String prefix = getAreaPrefix().getArea();
        if (districtSuffixList.isEmpty()) {
            return Collections.singletonList(prefix); // JDK1.8替代List.of(prefix)
        }
        return districtSuffixList.stream()
                .filter(StringUtils::isNotBlank)
                .map(suffix -> {
                    if (prefix.contains("460100") || prefix.contains("460200") || prefix.contains("460300")) {
                        return prefix + "," + suffix;
                    }
                    return prefix;
                })
                .distinct()
                .collect(Collectors.toList());
    }

    @Override
    public int supportRoleLevel() {
        return 3;
    }
}
